package leetcode_1_200;

import java.util.Arrays;

public class LeeCode_128 {
    public static void main(String[] args) {
        System.out.println(longestConsecutive(new int[]{100, 4, 200, 1, 3, 2}));
        System.out.println(longestConsecutive(new int[]{0,3,7,2,5,8,4,6,0,1}));
    }
    private static int longestConsecutive(int[] nums) {
        if (nums == null || nums.length == 0)
            return 0;
        Arrays.sort(nums);
        int ans = 1;
        int res = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[i - 1])
                continue;
            if (nums[i] - 1 == nums[i - 1]) {
                ans++;
                continue;
            }
            res = Math.max(res, ans);
            ans = 1;
        }
        res = Math.max(res, ans);
        return res;
    }
}
